package com.whp.bean;

import com.whp.service.MessageService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.Ordered;

import java.util.Date;

/**
 * @author wanghp
 * @version 1.0
 * @date 2020/07/08 23:41
 */
public class BeanLifecycleDemo implements BeanNameAware, BeanPostProcessor, InitializingBean, Ordered, DisposableBean {

	public BeanLifecycleDemo() {
		//实例化MessageServiceImpl Bean会打印
		System.out.println(" instance BeanLifecycleDemo Bean");
	}


	@Override
	public void setBeanName(String name) {
		System.out.println("BeanNameAware:" + name);
	}


	public void initMethod() {
		System.out.println("BeanLifecycleDemo init method() :");
	}

	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		System.out.println("BeanLifecycleDemo bean:  :" + "beanName:" + beanName + "postProcessBeforeInitialization");
		return null;
	}

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		System.out.println("BeanLifecycleDemo bean:  :" + "beanName:" + beanName + "postProcessAfterInitialization");
		return null;
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		System.out.println("BeanLifecycleDemo afterPropertiesSet :");
	}

	@Override
	public int getOrder() {
		return 0;
	}

	@Override
	public void destroy() throws Exception {
		System.out.println("this is  BeanLifecycleDemo‘s  destroy");
	}
}
